package com.ruoyi.web.controller.system;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Setting;
import com.ruoyi.system.service.ISettingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 程序设置Controller
 *
 * @author ruoyi
 * @date 2024-09-06
 */
@RestController
@RequestMapping("/system/setting")
public class SettingController extends BaseController {
    @Resource
    private ISettingService settingService;

    /**
     * 查询程序设置列表
     */
    //@PreAuthorize("@ss.hasPermi('system:setting:list')")
    @GetMapping("/list")
    public TableDataInfo list(Setting setting) {
        startPage();
        List<Setting> list = settingService.selectSettingList(setting);
        return getDataTable(list);
    }

    /**
     * 查询程序设置列表
     */
    @GetMapping("/list_Anonymous")
    @Anonymous
    public TableDataInfo list_Anonymous(Setting setting) {
        startPage();
        List<Setting> list = settingService.selectSettingList(setting);
        return getDataTable(list);
    }

    /**
     * 导出程序设置列表
     */
    //@PreAuthorize("@ss.hasPermi('system:setting:export')")
    @Log(title = "程序设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Setting setting) {
        List<Setting> list = settingService.selectSettingList(setting);
        ExcelUtil<Setting> util = new ExcelUtil<Setting>(Setting.class);
        util.exportExcel(response, list, "程序设置数据");
    }

    /**
     * 获取程序设置详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:setting:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(settingService.selectSettingById(id));
    }

    /**
     * 新增程序设置
     */
    //@PreAuthorize("@ss.hasPermi('system:setting:add')")
    @Log(title = "程序设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Setting setting) {
        return toAjax(settingService.insertSetting(setting));
    }

    /**
     * 修改程序设置
     */
    //@PreAuthorize("@ss.hasPermi('system:setting:edit')")
    @Log(title = "程序设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Setting setting) {
        return toAjax(settingService.updateSetting(setting));
    }

    /**
     * 删除程序设置
     */
    //@PreAuthorize("@ss.hasPermi('system:setting:remove')")
    @Log(title = "程序设置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(settingService.deleteSettingByIds(ids));
    }
}
